﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ext.Net;

namespace Sharp.Web
{
    public static class ExtExtension
    {
        public static AjaxProxy.Builder Reader(this AjaxProxy.Builder input)
        {
            return input.Reader(Html.X().JsonReader().RootProperty("data"));
        }

        /// <summary>
        /// 默认值
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static AjaxProxy.Builder Post(this AjaxProxy.Builder input)
        {
            input.ActionMethods(actions =>
          {
              actions.Read = HttpMethod.POST;
          });

            return input;
        }

        public static Column.Builder Filter(this ColumnBase input, GridFilter filter)
        {
            return ((Column.Builder)input).Filter(filter);
        }

        //升级
        public static FieldTrigger.Builder<FieldTrigger, FieldTrigger.Builder> HideTrigger(this FieldTrigger.Builder<FieldTrigger, FieldTrigger.Builder> input, bool hide)
        {
            return input;
        }
        public static GridFilters.Builder Local(this GridFilters.Builder input, bool hide)
        {
            return input;
        }
        public static GridFilters.Builder Filters(this GridFilters.Builder input, params object[] objects)
        {
            return input;
        }

        //失败
        //public static Hidden.Builder AntiForgeryToken(this Hidden.Builder input)
        //{
        //    var field = new HtmlHelper(input.ViewContext, null).AntiForgeryToken().ToHtmlString();
        //    var beginIndex = field.IndexOf("value=\"", StringComparison.Ordinal) + 7;
        //    var endIndex = field.IndexOf("\"", beginIndex, StringComparison.Ordinal);
        //    return new HtmlString(field.Substring(beginIndex, endIndex - beginIndex));
        //    //return input.Reader(Html.X().JsonReader().RootProperty("data"));
        //}
    }
}